define(function(require, exports, module) {
    'use strict';
    
    var rk = require('rk');

    $.widget("rk.titleTab", {
        options: {},
        _create: function() {
            var me = this;
            var elem = me.element;
            var len = elem.children().size();
            var idx = 0;
            var header = '<div class="schedule_head">' + '<ul class="schedule_head_ul">';
            elem.children().each(function() {
                var child = $(this);
                var title = child.attr('title');
                child.attr('child_idx', idx);
                header = header + '<li idx="' + idx + '"><a href="#" class="' + (idx == 0 ? 'hover' : '') + '"">' + title + '</a></li>' + (idx < (len - 1) ? '<li><span class="divline">|</span></li>' : '');
                idx++;
            });
            header = header + '</ul></div>';

            header = '<div class="pop_head">' + header + '<a href="#" class="close_schedule"></a>' +
                '<span class="schedule_editor_title" style="display:' + (me.options.act == 'edit' ? 'block' : 'none') + '">'+rk.i18n('SCHEDULE_21')+'</span>' +
                '</div>';
            //style="visibility:'+(me.options.act == 'edit' ? 'visible' : 'hidden')+'"

            //elem.parent().prepend(header);
            elem.prepend(header);
            header = elem.parent().find('.pop_head');
            header.on("click", "a", function() {
                var a = $(this);
                var li = a.parent();
                var idx = li.attr('idx');
                if (!idx) return;
                elem.children().not('.pop_head').hide();
                var currentCon = elem.children('div[child_idx="' + idx + '"]');
                currentCon.show();
                header.find('a').removeClass('hover');
                a.addClass("hover");
                idx = idx + '';
                currentCon.find('div.type_content_edit>input').focus();

                //切换tab时隐藏参与人的下拉窗口
                $('.ui-powerinput-menu').hide();
                return false;
            });
            window.setTimeout(function() {
                elem.find('.schedule_panel').find('div.type_content_edit>input').focus();
            }, 50);
            me.headerObj = header;
        },
        headerObj: null,
        select: function(idx) {
            var me = this;
            var elem = me.element;
            var a = me.headerObj.find('li[idx="' + idx + '"] > a');
            a.click();
        }
    });
});